package com.xiaodai.miaosha.controller;


import com.xiaodai.miaosha.entity.Msuser;
import com.xiaodai.miaosha.service.IMsuserService;
import com.xiaodai.miaosha.service.IOrdersService;
import com.xiaodai.miaosha.vo.OrderDeatilVo;
import com.xiaodai.miaosha.vo.RespBean;
import com.xiaodai.miaosha.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaodai
 * @since 2022-04-12
 */
@Controller
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private IOrdersService orderService;
    @Autowired
    private IMsuserService userService;

    @GetMapping("/detail")
    @ResponseBody
    private RespBean detail(@CookieValue("userTicket") String ticket, HttpServletRequest request, HttpServletResponse response, Long orderId){
        Msuser Msuser = userService.getUserByCookie(ticket,request,response);
        if (Msuser == null){
            return RespBean.error(RespBeanEnum.SESSION_ERROR);
        }
        OrderDeatilVo order = orderService.detail(orderId);
        return RespBean.success(order);
    }
}
